package at.chl.genetic.function.math.random;

import java.util.List;

import at.chl.genetic.function.math.node.builder.AddFunctionNodeBuilder;
import at.chl.genetic.function.math.node.builder.ConstantNodeBuilder;
import at.chl.genetic.function.math.node.builder.IfBiggerFunctionNodeBuilder;
import at.chl.genetic.function.math.node.builder.IfEqualFunctionNodeBuilder;
import at.chl.genetic.function.math.node.builder.IfLesserFunctionNodeBuilder;
import at.chl.genetic.function.math.node.builder.ParamXNodeBuilder;
import at.chl.genetic.function.math.node.builder.ParamYNodeBuilder;
import at.chl.genetic.function.math.node.builder.SubFunctionNodeBuilder;
import at.chl.genetic.node.IDecisionNode;
import at.chl.genetic.node.builder.INodeBuilder;
import at.chl.genetic.random.AbstractRandomDecisionNodeFactory;

public class RandomMathDecisionNodeFactory extends
		AbstractRandomDecisionNodeFactory {

	
	
	//Need to develope a way to build functions and statement a flexible abstrct way
	
	public RandomMathDecisionNodeFactory() {
		super();
		registerDefaultMathNodeBuilders();
	}
	public RandomMathDecisionNodeFactory(List<INodeBuilder> nodeBuilders) {
		super(nodeBuilders);
		registerDefaultMathNodeBuilders();
	}
	
	private void registerDefaultMathNodeBuilders() {
		registerDecisionNodeBuilder(new ConstantNodeBuilder());
		registerDecisionNodeBuilder(new ParamXNodeBuilder());
		registerDecisionNodeBuilder(new ParamYNodeBuilder());
		registerDecisionNodeBuilder(new AddFunctionNodeBuilder());
		registerDecisionNodeBuilder(new SubFunctionNodeBuilder());
		registerDecisionNodeBuilder(new IfBiggerFunctionNodeBuilder());
		registerDecisionNodeBuilder(new IfEqualFunctionNodeBuilder());
		registerDecisionNodeBuilder(new IfLesserFunctionNodeBuilder());
		
	}
	@Override
	public IDecisionNode createRandomNode(boolean allowChilds) {
		
		
		//get a random nodebuilder index
		long index=MathRandomUtil.getRandomLong(getRegisteredNodeBuilders().size()-1);
		
		if(index<0){
			//EXC
		}
		//get the random ronebuilder
		INodeBuilder nodeBuilder = getRegisteredNodeBuilders().get((int)index);
		
		//build the random node
		IDecisionNode node=nodeBuilder.buildNode();
		
		//to a recursive method call for a needed childnode, 
		//so it will get childnodes aswell, and those too etc.
		if(!allowChilds){
			if(node.getChildrenCount()>0){
				//recursive call
				node=createRandomNode(false);
			}
		}
			
			
			
		return node;
			
		
	}
	
	
	




	

	

}
